package cn.chen.sparkproject.dao.impl;

import cn.chen.sparkproject.dao.ITaskDAO;
import cn.chen.sparkproject.domain.Task;
import cn.chen.sparkproject.jdbc.JdbcHelper;

import java.io.FileOutputStream;
import java.sql.ResultSet;

public class TaskDaoImpl implements ITaskDAO{

    @Override
    public Task findById(long taskId) {
        final Task task = new Task();
        String sql = "select * from task where task_id = ?";
        Object[] params = new Object[]{taskId};
        JdbcHelper jdbcHelper = JdbcHelper.getInstance();

        jdbcHelper.executeQuery(sql, params, new JdbcHelper.QueryCallback() {
            @Override
            public void process(ResultSet rs) throws Exception {
                if(rs.next()){
                    long taskId = rs.getInt(1);
                    String taskName = rs.getString(2);
                    String createTime = rs.getString(3);
                    String startTime = rs.getString(4);
                    String finishTime = rs.getString(5);
                    String taskType = rs.getString(6);
                    String taskStatus = rs.getString(7);
                    String taskParam = rs.getString(8);
                    task.setTaskId(taskId);
                    task.setTaskName(taskName);
                    task.setCreateTime(createTime);
                    task.setStartTime(startTime);
                    task.setFinishTime(finishTime);
                    task.setTaskType(taskType);
                    task.setTaskStatus(taskStatus);
                    task.setTaskParam(taskParam);
                }
            }
        });
        return task;
    }

}
